<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="账号类型" prop="accountType">
            <el-select v-model="queryParams.accountType" placeholder="请选择账号类型" clearable style="width: 240px">
              <el-option v-for="dict in biz_account_type" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="支付方式" prop="paymentWay">
            <el-select v-model="queryParams.paymentWay" placeholder="支付方式" clearable style="width: 240px">
              <el-option v-for="dict in biz_payment_way" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>
    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getStat"></right-toolbar>
        </el-row>
      </template>
      <el-table v-loading="loading" :data="cashierCountList" class="tableEmpty" border>
        <el-table-column type="index" label="序号" width="60px">
          <!-- 自定义索引 (可选) -->
          <template #default="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="金额区间" align="center" prop="amountRange" />
        <el-table-column label="可用数量" align="center" prop="cnt">
          <template #default="scope">
            <el-link type="danger" :underline="true" @click="handleView(scope.row)">{{ scope.row.cnt }}</el-link>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog :title="dialog.title" v-model="dialog.visible" width="680px" append-to-body>
      <el-card>
        <el-table v-loading="loading" :data="cashierList" class="tableEmpty">
          <el-table-column label="账户姓名" align="center" prop="accountName" />
          <el-table-column label="账户标识" align="center" prop="accountKey" />
          <el-table-column label="账户类型" align="center" prop="accountType" />
          <el-table-column label="二维码地址" align="center" prop="payUrl" />
          <el-table-column label="二维码图片" align="center" prop="payImage">
            <template #default="scope">
              <el-image :src="scope.row.payImage" :preview-src-list="[scope.row.payImage]" style="width: 50px; height: 50px" />
            </template>
          </el-table-column>
          <el-table-column label="授信余额" align="center" prop="balance">
            <template #default="scope">
              {{ scope.row.balance / 100 }}
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { statCashierBase,cashierAvailableList } from '@/api/stat';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { biz_payment_way,biz_account_type } = toRefs<any>(proxy?.useDict('biz_payment_way','biz_account_type'));

const cashierCountList = ref([]);
const showSearch = ref(true);
const loading = ref(true);
const cashierList = ref([]);
const queryParams = ref({accountType:'', paymentWay:'',amountRange:''});
const dialog = reactive<DialogOption>({
  visible: false,
  title: '账号详情'
});
const getStat = (params: any) => {
  loading.value = true;
  statCashierBase(params).then(res => {
    console.log(res)
    cashierCountList.value = res.data;
  }).finally(()=>{
    loading.value = false;
  })
}

const resetQuery = () => {
  queryParams.value.accountType = ''
  queryParams.value.paymentWay = ''
  getStat(queryParams.value);
}
const handleQuery = () => {
    getStat(queryParams.value);
}

const handleView = (row?: any) => {
  dialog.visible = true
  queryParams.value.amountRange = row.amountRange
  cashierList.value = [];
  cashierAvailableList(queryParams.value).then(res => {
    cashierList.value = res.data
  })
}

onMounted(() => {
  getStat(queryParams.value);
});
</script>

<style scoped lang="scss">

</style>
